<template>
	<view>
		<view class="box">
			<view class="box-name">
				<view class="title">
					<text>家族名称</text>
				</view>
				<view class="input">
					<input @input="changeGroupName" maxlength="10" type="text" placeholder="请输入家族名称" />
					<text>{{num}}/10</text>
				</view>
			</view>
			<view class="box-img">
				<view class="title">
					<text>家族头像</text>
				</view>
				<view class="img">
					<view class="img-add" v-if="head == ''">
						<image :src="addImg" @click="addHead"></image>
					</view>
					<view class="img-head" v-else>
						<image :src="head"></image>
					</view>

				</view>
			</view>

		</view>
	</view>
</template>

<script>
	import {
		chooseIamgeFromAlbum
	} from '@/api/uniapp/uni.js'
	import {
		uploadFile
	} from '@/api/http/common.js'

	export default {
		data() {
			return {
				addImg: require('@/static/img/msg/user/01.svg'),
				num: 0,
				head: ''
			}
		},
		methods: {
			changeGroupName(e) {
				//console.log(e)
				var groupName = e.detail.value
				this.num = groupName.length
				if (this.num == 0) {
					this.$emit('changeGroupName', uni.getStorageSync('nickname') + '创建的群聊')
				}
				this.$emit('changeGroupName', groupName)
			},
			addHead() {
				var that = this
				chooseIamgeFromAlbum().then(res => {
					//console.log(res)
					uploadFile(res).then(result => {
						if (result.data.pubInfo.code !== 0) {
							return uni.$showMsg(result.data.pubInfo.message);
						}
						that.head = result.data.busInfo

						that.changeHead()
					})
				})
			},
			changeHead() {
				this.$emit('changeHead', this.head)
			}
		}
	}
</script>

<style lang="scss" scoped>
	.box {
		margin-left: 5%;
		width: 90%;
		// height: 330px;
		// background: rgba(255, 255, 229, 1);
		// border-radius: 40rpx;

		.title {
			margin: 20rpx 0;

			text {
				color: rgba(0, 0, 0, 1);
				font-size: 34rpx;
				font-weight: 550;
			}
		}

		.box-name {
			margin: 30rpx;

			.input {
				display: flex;
				justify-content: space-between;

				input {
					font-size: 32rpx;
				}

			}
		}

		.box-img {
			margin: 30rpx;

			.img-add {
				image {
					width: 160rpx;
					height: 160rpx;
					border-radius: 50%;
				}
			}

			.img-head {
				image {
					width: 160rpx;
					height: 160rpx;
					border-radius: 50%;
				}
			}
		}

	}
</style>
